#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>

void copy(int src_fd, int dst_fd){
  char buf[512];
  int count;
  while(count = read(src_fd,buf,512)){
    write(dst_fd,buf,count);
  }
}

int main(int argc, char* argv[]){
  int fd;
  if(argc == 1){
    char buf[512];
    int count;
    while(count = read(0,buf,512)){
        write(1,buf,count);
    }
  }
  else{
    fd = open(argv[1],O_RDONLY);
  }
  copy(fd,1);
  close(fd);
  return 0;
}
